<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增软件用户')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-appuser-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">账号：</label>
            <div class="col-sm-8">
                <input name="userId" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">头像：</label>
            <div class="col-sm-8">
                <input id="iconUrl" name="iconUrl" class="form-control" type="text" readonly>
                <div class="photo-add">
                    <input  type="file" accept="image/*"
                            name="uploader-input"
                            class="uploader-file"
                            id="upload">
                </div>
                <div id="box"></div>

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">昵称：</label>
            <div class="col-sm-8">
                <input name="name" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">手机号：</label>
            <div class="col-sm-8">
                <input name="phone" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否删除：0存在 1删除：</label>
            <div class="col-sm-8">
                <input name="delFlag" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">邮箱：</label>
            <div class="col-sm-8">
                <input name="mail" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea name="remark" class="form-control"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "system/appuser"
    $("#form-appuser-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-appuser-add').serialize());
        }
    }

    $("input[name='addtime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
    document.getElementById('upload').addEventListener('change', function (event) {
        var $file = event.currentTarget;
        var formData = new FormData();
        var file = $file.files;
        formData = new FormData();
        formData.append("file", file[0]);
        $.ajax({
            url: ctx + "common/upload",
            type: 'POST',
            dataType: 'json',
            data: formData,
            contentType: false,
            processData: false
        })
            .done(data => {
                console.log(data);
                $('#logoImg').val(data.url);
                $('#box').append(`<div class="photo-item">
            <img class="item-image" width="100%" height="100%" src="${data.url}"/>
        </div>`);
            })
            .fail(data => {
                console.log(data);
            });
    });
</script>
</body>
</html>
